<template>
  <div class="backImg">
    <div class="loginBox">
      <div class="imgBox">
        <div class="welContain">
          <span>Welcome</span>
          <span>教师管理系统</span>
        </div>
      </div>
      <div class="formBox">
        <el-form :model="ruleForm" status-icon :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
          <el-form-item class="inputcontainer" label="账号" prop="username" label-width="50px">
            <el-input prefix-icon="el-icon-user" v-model="ruleForm.username" placeholder="请输入账号"></el-input>
          </el-form-item>
          <el-form-item class="inputcontainer" label="密码" prop="password" label-width="50px">
            <el-input prefix-icon="el-icon-key" type="password" v-model="ruleForm.password" autocomplete="off"
              placeholder="请输入密码"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="submitForm('ruleForm')">登陆</el-button>
          </el-form-item>
        </el-form>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  // 组件名称
  name: 'loginView',
  data() {
    var validatePass = (rule, value, callback) => {
      if (value === '') {
        callback(new Error('请输入密码'));
      }
      else {
        callback()
      }
    };
    var validateAccount = (rule, value, callback) => {
      if (value === '') {
        callback(new Error('请输入账号'));
      }
      else {
        callback()
      }
    };
    return {
      ruleForm: {
        username: '',
        password: '',
      },
      rules: {
        password: [
          { validator: validatePass, trigger: 'blur' }
        ],
        username: [
          { validator: validateAccount, trigger: 'blur' }
        ],
      }
    };
  },
  methods: {
    submitForm(formName) {
      console.log(this.ruleForm);
      this.$refs[formName].validate((valid) => {
        if (valid) {
          // this.$store.dispatch('userLogin', this.ruleForm).then(() => {
          //   setTimeout(() => {
          //     this.$message({
          //       message: "登录成功",
          //       type: 'success'
          //     })
          //   }, 1000);

          // }).catch(err => {
          //   console.log(err)
          // })
          if (this.ruleForm.username === 'admin') {
            localStorage.setItem('user','manager')
            this.$router.push({
              name:'managePage'
            })
          }
          else{
            localStorage.setItem('user','teacher')
            this.$router.push(
              {
              name:'teacherPage'
            })
          }
        }
      });
    }
  }
}
</script> 

<style scoped lang='less'>
.backImg {
  height: 100%;
  width: 100%;
  position: absolute;
  background: url(@/assets/th.jpg) fixed no-repeat;
  background-size: cover;
  overflow: hidden;

  .loginBox {
    width: 804px;
    height: 400px;
    margin: 12% auto;
    position: relative;
    z-index: 10;

    .imgBox {
      height: 100%;
      width: 400px;
      float: left;

      .welContain {
        width: 100%;
        height: 100px;
        margin: 38% auto;

        span {
          font-size: 30px;
          display: block;
          text-align: center;
          margin-bottom: 10px;
          color: aliceblue;
          text-shadow: 3px 3px 3px rgb(98, 98, 98);
        }
      }
    }

    .imgBox::before {
      content: "";
      width: calc(50%);
      height: calc(100%);
      position: absolute;
      top: 2px;
      left: 5px;
      overflow: hidden;
      background: inherit;
      box-shadow: inset 0 0 0 200px rgba(255, 255, 255, 0.45);
      filter: blur(5px);
      border-radius: 25px 0 0 25px;
      z-index: -1;
    }

    .formBox {
      background-color: rgb(249, 245, 245);
      border: 1px solid rgb(175, 222, 240);
      height: 100%;
      width: 400px;
      display: flex;
      align-items: center;
      border-radius: 0 25px 25px 0;
      position: relative;

      .el-form {
        position: absolute;
        top: 25%;
        left: 15%;

        .el-form-item {
          margin-bottom: 40px;

          // // border-bottom: 1px solid rgb(131, 131, 131) ;
          // .inputcontainer>>>.el-input__inner {
          //   border: none;
          //   border-bottom: 1px solid #a8a8a8;
          //   width: 220px;
          // }
        }
      }
    }
  }
}
</style>
